local base = piece "base"
local wheel1 = piece "wheel1"
local wheel2 = piece "wheel2"
local wheel3 = piece "wheel3"
local cooler1 = piece "cooler1"
local cooler2 = piece "cooler2"
local cooler3 = piece "cooler3"

local function OpenCoolers ()
        while(true) do
		Turn(cooler1, x_axis, -0.2, 1)
		WaitForTurn(cooler1, x_axis)
		Sleep(1000)
		Turn(cooler1, x_axis, 0, 1)
		WaitForTurn(cooler1, x_axis)
		Sleep(1000)

                Turn(cooler2, x_axis, 0.2, 1)
                WaitForTurn(cooler2, x_axis)
                Sleep(1000)
                Turn(cooler2, x_axis, 0, 1)
                WaitForTurn(cooler2, x_axis)
                Sleep(1000)

                Turn(cooler3, x_axis, -0.2, 1)
                WaitForTurn(cooler3, x_axis)
                Sleep(1000)
                Turn(cooler3, x_axis, 0, 1)
                WaitForTurn(cooler3, x_axis)
                Sleep(1000)

        end
end

local function Initialize()
        Signal(2)
        SetSignalMask(1)

	Spin(wheel1, x_axis, -1, 0.1)
	Spin(wheel2, x_axis, 1, 0.1)
	Spin(wheel3, x_axis, 1, 0.1)

	StartThread(OpenCoolers())

        return true
end

local function Deinitialize()
        Signal(1)
        SetSignalMask(2)

        return true
end

function script.Create ( )
	Turn(wheel2, y_axis, -1.04719755)
	Turn(wheel3, y_axis, 1.04719755)
	
	Turn(cooler1, y_axis, 1.04719755)
	Turn(cooler3, y_axis, -1.04719755)
end

function script.Activate ( )
        StartThread(Initialize)

end

function script.Deactivate ( )
        StartThread(Deinitialize)
end
